﻿using System;

namespace CollegeSim.Domain.Entities
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 2/4/2014

    #region [ Updates ]

    // Author: Ryan Redburn
    // Date: 5/6/2014
    // Revisions: Changed Person to reflect 2.0 changes

    #endregion

    /// <summary>
    /// Abstract class used to represent a person. Used as a base for Student and Instructor.
    /// </summary>
    public abstract class Person
    {
        #region [ Fields ]

        private string _firstName;
        private string _lastName;
        private string _phoneNumber;
        private string _email;

        #endregion

        #region [ Properties ]

        // Person Identifier
        // Set by DB
        public int PersonID { get; set; }

        // FirstName
        // Cannot be null or empty and length must be less than or equal to twenty characters
        public string FirstName
        {
            get { return _firstName; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length <= 20)
                    {
                        _firstName = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "FirstName must be twenty characters or less.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "FirstName cannot be null or empty.");
                }
            }
        }

        // LastName
        // Cannot be null or empty and length must be less than or equal to thirty characters
        public string LastName
        {
            get { return _lastName; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length <= 30)
                    {
                        _lastName = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "LastName must be thirty characters or less.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "LastName cannot be null or empty.");
                }
            }
        }

        // PhoneNumber
        // Format: 000-000-0000
        public string PhoneNumber
        {
            get { return _phoneNumber; }
            set
            {
                if (value == null || value.Length <= 15)
                {
                    _phoneNumber = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "PhoneNumber cannot be more than fifteen characters in length.");
                }
            }
        }

        // Email Address
        // Format: person@domain.extension
        public string Email
        {
            get { return _email; }
            set
            {
                if (value == null || value.Length <= 50)
                {
                    _email = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "Email cannot be more than fifty characters in length.");
                }
            }
        }

        #endregion
    }
}
